﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Bioinformatics.Algorithms;

namespace pAligner
{
    class Program
    {
        static void Main(string[] args)
        {
            //Get all fasta file paths 
            var fastaFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.fasta");
            //print out headers of each file
            for(var f = 0; f < fastaFiles.Length; f++)
            {
                var textReader = new StreamReader(fastaFiles[f]);
                Console.WriteLine("[" + f + "]\t" + textReader.ReadLine());
                textReader.Close();
            }
            //get sequences to align
            Console.Write("Please indicate sequences to align by entering the sequence index: ");
            //read indexes from user
            var selectionString = Console.ReadLine();
            //separate indexs and convert to integer
            var strIndexArray = selectionString.Split(' ');
            var intIndexArray = new int[strIndexArray.Length];
            for (int i = 0; i < strIndexArray.Length; i++)
                intIndexArray[i] = int.Parse(strIndexArray[i]);
            
            //construct distance matrix for all alignments
            var distanceMatrix = new float[intIndexArray.Length, intIndexArray.Length];
            
            //complete alignments
            for (var i = 0; i < intIndexArray.Length; i++)
                for (var j = 0; j < intIndexArray.Length; j++)
                    if(i != j)
                        distanceMatrix[i, j] = SequenceAligner.AlignPair("", "", null, 0, 0);
            
            //print out distance matrix
            var distanceTotals = new float[intIndexArray.Length];
            Console.WriteLine("Distance Matrix:");
            for (var i = 0; i < intIndexArray.Length; i++)
            {
                for (var j = 0; j < intIndexArray.Length; j++)
                {
                    Console.Write(distanceMatrix[i, j].ToString("N2") + "\t");
                    distanceTotals[j] += distanceMatrix[i, j];
                }
                Console.WriteLine();
            }
            //print out distance totals
            for (var i = 0; i < intIndexArray.Length; i++)
                Console.Write(distanceTotals[i].ToString("N2") + "\t");
            Console.Read();
        }
    }
}
